package com.webchat.admin.service;


import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.exception.BusinessException;
import com.webchat.domain.vo.request.publicaccount.SaveArticleRequestVO;
import com.webchat.domain.vo.response.publicaccount.ArticleBaseResponseVO;
import com.webchat.rmi.pgc.OfficialArticleClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OfficialArticleService {


    @Autowired
    private OfficialArticleClient officialArticleClient;


    public Long submit(SaveArticleRequestVO saveArticleRequest) {

        APIResponseBean<Long> responseBean = officialArticleClient.submit(saveArticleRequest);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new BusinessException("公众号文章提交失败！");
    }

    public APIPageResponseBean<ArticleBaseResponseVO> page(Integer pageNo, Integer pageSize) {

        APIResponseBean<APIPageResponseBean<ArticleBaseResponseVO>> responseBean =
                officialArticleClient.page(pageNo, pageSize);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        return null;
    }
}
